import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
//按需导入 element
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  // 配置@
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  // 配代理服务器解决跨域问题
  server: {
    proxy: {
      "/api": {
        target: "http://xue.cnkdl.cn:9082/mall-admin",
        changeOrigin: true,
        // rewrite如果没写，我们在请求的时候，会向服务器发送请求的地址，会带上在axios封装里面的baseURL
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
});
